package com.sr.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.data.*;

public class AddBase extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		baseDataService bds = new baseDataService();
		String projectName = request.getParameter("pName");
				
		srProject  srp =new srProject();
		srp.setprojectID(request.getParameter("pID"));
		srp.setprojectName(request.getParameter("pName"));
		srp.setDepartment(request.getParameter("department"));
		srp.setBeginDate(request.getParameter("bDate"));
		srp.setEndDate(request.getParameter("eDate"));
		srp.setProjectLeader(request.getParameter("pLeader"));
		srp.setMainMembers(Integer.parseInt(request.getParameter("mainMembers")));
		srp.setFromOrg(request.getParameter("fromOrg"));
		srp.setLevelProject(request.getParameter("levelProject"));
		srp.setTypeProject( request.getParameter("typeProject"));
		srp.setDiscipline(request.getParameter("discipline"));
		
		int count = bds.GetCountOfProjectByID(request.getParameter("pID"));
		if(count == 0){
			bds.AddProject(srp);
			srp = bds.CheckProject(srp);
			
			request.getSession().setAttribute("updateBaseProject", srp);
			response.sendRedirect("/scientific/jsp/base/baseUpdate.jsp");
		}
		else{
			request.setAttribute("ExpAddError", "项目：'"+projectName+"'已存在，请重新输入!");
			request.setAttribute("updateBase", srp);
			request.getRequestDispatcher("/jsp/base/addBaseinfo.jsp").forward(request, response);		
		}		
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);		
	}
}

